package com.ymh.git.thread.juc.threadpool;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by aivin on 2018/11/7.
 */
public class ScheduleWorker implements Runnable {

    public final static int Normal = 0;//普通任务类型
    public final static int HasException = 0;//会抛出异常的任务类型
    public final static int ProcessException = 0;//抛出异常但会捕捉的任务类型

    public static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    private int taskType;

    public ScheduleWorker(int taskType) {
        this.taskType = taskType;
    }

    @Override
    public void run() {
        if (taskType == HasException) {
            System.out.println(simpleDateFormat.format(new Date()) + " Exception be made");
            throw new RuntimeException("ExceptionHappen");
        } else if (taskType == ProcessException) {
            try {
                System.out.println(simpleDateFormat.format(new Date()) + " Exception be made, will be catch");
            } catch (Exception e) {
                System.out.println("We catch Exception");
            }
        } else {
            System.out.println(simpleDateFormat.format(new Date()) + "Normal...");
        }
    }
}
